#include <iostream>
#include <vector>
#include <cstdlib>
#include <ctime>
#include <math.h>
#include <algorithm>
using namespace std;

void nextPermutation(vector<int>& nums) {
    short size=nums.size();
    int temp;
    for(short i=size-1;i>=1;i--){
        if(nums[i]>nums[i-1]){
            for(short j=i;j<size;j++){
                if(nums[j]>nums[i-1]&&(j==size-1||nums[j+1]<=nums[i-1])){                    temp=nums[i-1];
                    nums[i-1]=nums[j];
                    nums[j]=temp;
                    vector<int>::iterator it1(&nums[i]);
                    sort(it1,nums.end());
                    return;
                }
            }
        }
    }
    sort(nums.begin(),nums.end());
}

int main(){
    vector<int>a={1,5,1};
    nextPermutation(a);
    for(auto temp:a){
        cout<<temp<<",";
    }
    return 0;
}